
////////////////////////////////////////////////////////////////////////////////////////////////
/* please refer to Appendix 1 for definitions and sources of all variables in the paper       */
/* note that in all pseudo datasets, gvkey has been annonymized to '99999'.                   */
/* please install the following external packages: outreg2 reghdfe ppmlhdfe ftools            */
////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////
/* FIRM-STATE-MONTH ANALYSES      */
////////////////////////////////////

use "ns_uncertainty_lightcast_firm_state_month", clear

/* GEN DESCRIPTIVE STATS IN TABLE 1 */

// generate firm-job state-month-year characteristics 
outreg2 using lightcast_firmdescriptive.xls, replace sum(detail) keep(ln_totalassets firm_age ROA CAPEX TOBINQ expose_gen_econuncertainty ln_fulltimeposts no_fulltimeposts) eqkeep (N mean sd p25 p50 p75)

// set control variables and fixed effects for regressions
macro drop _all 
global controls ln_totalassets firm_age ROA CAPEX TOBINQ  expose_gen_econuncertainty
global fixed_effects gvkey countyfips_firmhq#year countyfips_joblocation#year  n2#year month

/* GEN RESULTS IN TABLE 2 */

reghdfe ln_fulltimeposts pre1q_election $controls, absorb($fixed_effects) cluster(gvkey) /*column 1 */
reghdfe ln_fulltimeposts pre2q_election $controls, absorb($fixed_effects) cluster(gvkey) /*column 2 */
reghdfe ln_fulltimeposts pre1q_election pre2q_election $controls, absorb($fixed_effects) cluster(gvkey) /*column 3 */

/* GEN RESULTS IN TABLE 3A */

reghdfe ln_fulltimeposts pre1q_election pre2q_election $controls, absorb($fixed_effects) cluster(gvkey) /*column 1 */
reghdfe ln_parttimeposts pre1q_election pre2q_election $controls, absorb($fixed_effects) cluster(gvkey) /*column 2 */
reghdfe frac_fulltimeposts pre1q_election  pre2q_election $controls, absorb($fixed_effects) cluster(gvkey) /*column 3 */

/* GEN RESULTS IN TABLE 3B */

gen Q1HQ= pre1q_election*isHQ
gen Q2HQ= pre2q_election*isHQ
gen Q1nonHQ= pre1q_election*isnotHQ
gen Q2nonHQ= pre2q_election*isnotHQ

reghdfe ln_fulltimeposts Q1HQ  Q2HQ  Q1nonHQ  Q2nonHQ isHQ $controls, absorb($fixed_effects) cluster(gvkey)
test Q1HQ  + Q2HQ = Q1nonHQ + Q2nonHQ

/* GEN RESULTS IN TABLE 3C */

gen Q1highremote= pre1q_election*high_remotework
gen Q2highremote= pre2q_election*high_remotework
gen Q1lowremote= pre1q_election*low_remotework
gen Q2lowremote= pre2q_election*low_remotework

reghdfe ln_fulltimeposts Q1highremote  Q2highremote  Q1lowremote Q2lowremote  high_remotework $controls , absorb($fixed_effects) cluster(gvkey)
test Q1highremote+ Q2highremote = Q1lowremote + Q2lowremote

/* GEN RESULTS IN TABLE 4 */

gen Q1highunion= pre1q_election*high_union
gen Q2highunion= pre2q_election*high_union
gen Q1lowunion= pre1q_election*low_union
gen Q2lowunion= pre2q_election*low_union

reghdfe ln_fulltimeposts Q1highunion  Q2highunion  Q1lowunion Q2lowunion  high_union $controls, absorb($fixed_effects) cluster(gvkey)  /*column 1 */
test Q1highunion +  Q2highunion =  Q1lowunion + Q2lowunion

reghdfe ln_fulltimeposts Q1highunion  Q2highunion  Q1lowunion Q2lowunion high_union $controls if no_union_googletrends==1, absorb($fixed_effects) cluster(gvkey)  /*column 2 */
test Q1highunion +  Q2highunion =  Q1lowunion + Q2lowunion

reghdfe ln_fulltimeposts Q1highunion  Q2highunion  Q1lowunion Q2lowunion high_union $controls if no_union_ballot==1, absorb($fixed_effects) cluster(gvkey)  /*column 3 */
test Q1highunion +  Q2highunion =  Q1lowunion + Q2lowunion

reghdfe ln_fulltimeposts Q1highunion  Q2highunion  Q1lowunion Q2lowunion high_union $controls if no_union_ballot==1 &  no_union_googletrends==1, absorb($fixed_effects) cluster(gvkey)  /*column 4 */
test Q1highunion +  Q2highunion =  Q1lowunion + Q2lowunion

/* GEN RESULTS IN TABLE 6 */

gen Q1large= pre1q_election*large_firm
gen Q2large= pre2q_election*large_firm
gen Q1small= pre1q_election*small_firm
gen Q2small= pre2q_election*small_firm

reghdfe ln_fulltimeposts  Q1small Q2small Q1large Q2large small_firm $controls  , absorb($fixed_effects) cluster(gvkey) /*column 1 */
test Q1large + Q2large = Q1small + Q2small 

gen Q1oldfirm= pre1q_election*oldfirm
gen Q2oldfirm= pre2q_election*oldfirm
gen Q1youngfirm= pre1q_election*youngfirm
gen Q2youngfirm= pre2q_election*youngfirm

reghdfe ln_fulltimeposts  Q1youngfirm Q2youngfirm Q1oldfirm Q2oldfirm youngfirm $controls, absorb($fixed_effects) cluster(gvkey) /*column 2 */
test Q1oldfirm + Q2oldfirm = Q1youngfirm + Q2youngfirm 

gen Q1highSA= pre1q_election*high_sizeageindex
gen Q2highSA= pre2q_election*high_sizeageindex
gen Q1lowSA= pre1q_election*low_sizeageindex
gen Q2lowSA= pre2q_election*low_sizeageindex

reghdfe ln_fulltimeposts   Q1highSA Q2highSA Q1lowSA Q2lowSA high_sizeageindex $controls, absorb($fixed_effects) cluster(gvkey) /*column 3 */
test  Q1highSA + Q2highSA = Q1lowSA + Q2lowSA 

/* GEN RESULTS IN TABLE 7 */

gen Q1high_vega= pre1q_election*high_vega
gen Q2high_vega= pre2q_election*high_vega
gen Q1low_vega= pre1q_election*low_vega
gen Q2low_vega= pre2q_election*low_vega
 
reghdfe ln_fulltimeposts Q1high_vega Q2high_vega Q1low_vega Q2low_vega  high_vega $controls, absorb($fixed_effects) cluster(gvkey)
test Q1high_vega + Q2high_vega = Q1low_vega + Q2low_vega 

/* GEN RESULTS IN TABLE 8 */

reghdfe ln_fulltimeposts   pre1q_highlaborelection pre2q_highlaborelection pre1q_lowlaborelection pre2q_lowlaborelection $controls, absorb($fixed_effects) cluster(gvkey)
test pre1q_highlaborelection + pre2q_highlaborelection = pre1q_lowlaborelection + pre2q_lowlaborelection

/* GEN RESULTS IN TABLE 9 */

reghdfe ln_fulltimeposts pre1q_highepuelection pre2q_highepuelection pre1q_lowepuelection pre2q_lowepuelection $controls, absorb($fixed_effects) cluster(gvkey)
test pre1q_highepuelection + pre2q_highepuelection = pre1q_lowepuelection  + pre2q_lowepuelection

/* GEN RESULTS IN APPENDIX 2 */

ppmlhdfe   no_fulltimeposts pre1q_election pre2q_election $controls, absorb($fixed_effects) /*column 1 */
reghdfe ln_fulltimeposts pre1q_election pre2q_election $controls if year!=2012 & year!=2016 , absorb($fixed_effects) cluster(gvkey) /*column 2 */
reghdfe ln_fulltimeposts pre1q_election pre2q_election $controls, absorb(gvkey#year countyfips_joblocation#year month) cluster(gvkey) /*column 3 */
reghdfe ln_fulltimeposts pre1q_election pre2q_election $controls, absorb($fixed_effects) cluster(gvkey countyfips_joblocation) /*column 4 */

////////////////////////////////////
/* JOB-LEVEL ANALYSES             */
////////////////////////////////////

use "ns_uncertainty_lightcast_job", clear

/* GEN DESCRIPTIVE STATS IN TABLE 1 */

// generate job-level characteristics 
outreg2 using lightcast_jobdescriptive.xls, replace sum(detail) keep(zone5v1 zone45v123 req_exp req_substantialexp ln_totalskills ln_specialskills) eqkeep (N mean sd p25 p50 p75)

// set control variables 
macro drop _all 

// set control variables for regressions
global controls ln_totalassets firm_age ROA CAPEX TOBINQ expose_gen_econuncertainty
global fixed_effects gvkey countyfips_firmhq#year countyfips_joblocation#year n2#year month

/* GEN RESULTS IN TABLE 5A */

reghdfe zone5v1  pre1q_election pre2q_election $controls, absorb($fixed_effects) cluster(gvkey) /*column 1 */
reghdfe zone45v123  pre1q_election pre2q_election $controls, absorb($fixed_effects) cluster(gvkey) /*column 2 */

/* GEN RESULTS IN TABLE 5B */

reghdfe req_exp  pre1q_election pre2q_election $controls, absorb($fixed_effects) cluster(gvkey) /*column 1 */
reghdfe req_substantialexp  pre1q_election pre2q_election $controls, absorb($fixed_effects) cluster(gvkey) /*column 2 */

/* GEN RESULTS IN TABLE 5C */

reghdfe ln_totalskills  pre1q_election pre2q_election $controls, absorb($fixed_effects) cluster(gvkey) /*column 1 */
reghdfe ln_specialskills  pre1q_election pre2q_election $controls, absorb($fixed_effects) cluster(gvkey) /*column 2 */

////////////////////////////////////
/* REVELIO                        */
////////////////////////////////////

use "ns_uncertainty_revelio_firm_state_month.dta", clear

/* GEN DESCRIPTIVE STATS IN TABLE 1  */

// generate job-level characteristics 
outreg2 using revelio.xls, replace sum(detail) keep( ln_layoff ln_empinflow ln_empoutflow early_depart ) eqkeep (N mean sd p25 p50 p75)

// set control variables 
macro drop _all 

global controls ln_totalassets  firm_age ROA CAPEX TOBINQ  expose_gen_econuncertainty
global fixed_effects gvkey countyfips_firmhq#year countyfips_joblocation#year n2#year month

/* GEN RESULTS IN TABLE 10 */

reghdfe ln_layoff pre1q_election $controls, absorb($fixed_effects) cluster(gvkey) /*column 1 */
reghdfe ln_layoff  pre2q_election $controls, absorb($fixed_effects) cluster(gvkey) /*column 2 */
reghdfe ln_layoff pre1q_election pre2q_election $controls, absorb($fixed_effects) cluster(gvkey) /*column 3 */

/* GEN RESULTS IN TABLE 11 */

reghdfe ln_empinflow pre1q_election pre2q_election $controls, absorb($fixed_effects) cluster(gvkey) /*column 1 */
reghdfe ln_empoutflow pre1q_election pre2q_election $controls, absorb($fixed_effects) cluster(gvkey) /*column 2 */

/* GEN RESULTS IN TABLE 12 */
 
reghdfe early_depart pre1q_election $controls, absorb($fixed_effects) cluster(gvkey) /*column 1 */
reghdfe early_depart pre2q_election $controls, absorb($fixed_effects) cluster(gvkey) /*column 2 */
reghdfe early_depart pre1q_election pre2q_election $controls, absorb($fixed_effects) cluster(gvkey) /*column 3 */
